package com.fw.ui.view.profile.merchant.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.vaadin.dialogs.ConfirmDialog;

import com.fw.service.bean.ErrorBean;
import com.fw.service.file.bean.FileBean;
import com.fw.service.merchantprofile.bean.MerchantProfileBean;
import com.fw.ui.ApplicationUI;
import com.fw.ui.bao.FileBAO;
import com.fw.ui.bao.MerchantProfileBAO;
import com.fw.ui.bao.MessageBAO;
import com.fw.ui.util.SessionInfoUtils;
import com.fw.ui.util.UICommonUtils;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.common.ConfirmDialogWindow;
import com.fw.ui.view.event.AbstractButtonClickListener;
import com.fw.ui.view.profile.CreateMerchantProfileView;
import com.vaadin.ui.Button.ClickEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class CreateMerchantProfileSaveButtonClickListener extends AbstractButtonClickListener {

    private static Logger log = Logger.getLogger(CreateMerchantProfileSaveButtonClickListener.class.getName());
    private static final long serialVersionUID = 482478998438351054L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private MerchantProfileBAO merchantProfileBAO;
    @Autowired
    private MessageBAO messageBAO;
    @Autowired
    private UICommonUtils uiCommonUtils;
    @Autowired
    private FileBAO fileBAO;
    @Autowired
    private SessionInfoUtils sessionInfoUtils;

    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> click(ClickEvent event) throws Exception {
	final Map<String, Object> result = new HashMap<String, Object>();
	final CreateMerchantProfileView createMerchantProfileView = (CreateMerchantProfileView) this.getBasedComponent();
	final String merchantId = createMerchantProfileView.getTxtMerchantId().getValue();
	final String merchantNameTh = createMerchantProfileView.getTxtMerchantNameTh().getValue();

	String title = messageBAO.getMessage("com.fw.ui.view.profile.CreateMerchantProfileView.message.confirm.title");
	String okCaption = messageBAO.getMessage("application.button.ok.caption");
	String cancelCaption = messageBAO.getMessage("application.button.cancel.caption");

	String content = messageBAO.getMessageWithParams("com.fw.ui.view.profile.CreateMerchantProfileView.message.confirm.content",
		new String[] { merchantId, merchantNameTh });

	ConfirmDialogWindow.createConfirmDialog(createMerchantProfileView.getUI(), title, content, okCaption, cancelCaption,
		new ConfirmDialog.Listener() {
		    private static final long serialVersionUID = 1L;

		    @Override
		    public void onClose(ConfirmDialog dialog) {
			if (dialog.isConfirmed()) {
			    log.info("Confirm!");
			    Map<String, Serializable> mapResult = null;
			    try {

				String merchantStatus = (String) createMerchantProfileView.getCbbStatus().getValue();
				String merchantNameEn = createMerchantProfileView.getTxtMerchantNameEn().getValue();

				String companyNameEn = createMerchantProfileView.getTxtCompanyNameEn().getValue();
				String companyNameTh = createMerchantProfileView.getTxtCompanyNameTh().getValue();
				String merchantServiceType = (String) createMerchantProfileView.getCbbMerchantServiceType().getValue();
				String mccCode = (String) createMerchantProfileView.getCbbMCCCode().getValue();
				String statementName = createMerchantProfileView.getTxtStatementName().getValue();
				String businessRegNumber = createMerchantProfileView.getTxtBusinessRegistrationNumber().getValue();
				String countryRegion = (String) createMerchantProfileView.getCbbCountryRegion().getValue();
				String countryDomicile = (String) createMerchantProfileView.getCbbCountryDomicile().getValue();
				String mailingAddress = createMerchantProfileView.getTxtMailingAddress().getValue();
				String businessAddress = createMerchantProfileView.getTxtBusinessAddress().getValue();
				String faxNumber = createMerchantProfileView.getTxtFaxNumber().getValue();
				String url = createMerchantProfileView.getTxtUrl().getValue();
				String enquiryNumber = createMerchantProfileView.getTxtEnquiryNumber().getValue();
				String taxId = createMerchantProfileView.getTxtTaxId().getValue();
				Boolean isTestMerchant = createMerchantProfileView.getCbIsTestMerchant().getValue();

				String contact1Name = createMerchantProfileView.getTxtProjectContactName().getValue();
				String contact1Mobile = createMerchantProfileView.getTxtProjectContactMobile().getValue();
				String contact1Email = createMerchantProfileView.getTxtProjectContactEmailAddress().getValue();
				String contact1Phone = createMerchantProfileView.getTxtProjectContactPhone().getValue();

				String contact2Name = createMerchantProfileView.getTxtOperationContactName().getValue();
				String contact2Mobile = createMerchantProfileView.getTxtOperationContactMobile().getValue();
				String contact2Email = createMerchantProfileView.getTxtOperationContactEmailAddress().getValue();
				String contact2Phone = createMerchantProfileView.getTxtOperationContactPhone().getValue();

				String contact3Name = createMerchantProfileView.getTxtTechnicalContactName().getValue();
				String contact3Mobile = createMerchantProfileView.getTxtTechnicalContactMobile().getValue();
				String contact3Email = createMerchantProfileView.getTxtTechnicalContactEmailAddress().getValue();
				String contact3Phone = createMerchantProfileView.getTxtTechnicalContactPhone().getValue();

				String contact4Name = createMerchantProfileView.getTxtFinancialContactName().getValue();
				String contact4Mobile = createMerchantProfileView.getTxtFinancialContactMobile().getValue();
				String contact4Email = createMerchantProfileView.getTxtFinancialContactEmailAddress().getValue();
				String contact4Phone = createMerchantProfileView.getTxtFinancialContactPhone().getValue();

				MerchantProfileBean merchantProfileBean = new MerchantProfileBean();
				merchantProfileBean.setMerchantId(merchantId);
				merchantProfileBean.setMerchantStatus(merchantStatus);
				merchantProfileBean.setMerchantNameEn(merchantNameEn);
				merchantProfileBean.setMerchantNameTh(merchantNameTh);
				merchantProfileBean.setCompanyNameEn(companyNameEn);
				merchantProfileBean.setCompanyNameTh(companyNameTh);
				merchantProfileBean.setMerchantServiceType(merchantServiceType);
				merchantProfileBean.setMccCode(mccCode);
				merchantProfileBean.setStatementName(statementName);
				merchantProfileBean.setBusinessRegNumber(businessRegNumber);
				merchantProfileBean.setCountryRegion(countryRegion);
				merchantProfileBean.setCountryDomicile(countryDomicile);
				merchantProfileBean.setMailingAddress(mailingAddress);
				merchantProfileBean.setBusinessAddress(businessAddress);
				merchantProfileBean.setFaxNumber(faxNumber);
				merchantProfileBean.setUrl(url);
				merchantProfileBean.setEnquiryNumber(enquiryNumber);
				merchantProfileBean.setTaxId(taxId);

				merchantProfileBean.setContact1Name(contact1Name);
				merchantProfileBean.setContact1Mobile(contact1Mobile);
				merchantProfileBean.setContact1Email(contact1Email);
				merchantProfileBean.setContact1Phone(contact1Phone);

				merchantProfileBean.setContact2Name(contact2Name);
				merchantProfileBean.setContact2Mobile(contact2Mobile);
				merchantProfileBean.setContact2Email(contact2Email);
				merchantProfileBean.setContact2Phone(contact2Phone);

				merchantProfileBean.setContact3Name(contact3Name);
				merchantProfileBean.setContact3Mobile(contact3Mobile);
				merchantProfileBean.setContact3Email(contact3Email);
				merchantProfileBean.setContact3Phone(contact3Phone);

				merchantProfileBean.setContact4Name(contact4Name);
				merchantProfileBean.setContact4Mobile(contact4Mobile);
				merchantProfileBean.setContact4Email(contact4Email);
				merchantProfileBean.setContact4Phone(contact4Phone);

				merchantProfileBean.setIsTestMerchant(isTestMerchant);

				ApplicationUI applicationUI = (ApplicationUI) createMerchantProfileView.getUI();
				sessionInfoUtils.setSessionInfoDetails(merchantProfileBean, applicationUI.getAuthenticationBean(),
					applicationUI.getLocale());

				MerchantProfileBean oldMerchantProfileBean = createMerchantProfileView.getMerchantProfileBean();
				if (oldMerchantProfileBean.getFileExtension() != null && oldMerchantProfileBean.getContentType() != null
					&& oldMerchantProfileBean.getLogoImageByteArray() != null) {
				    FileBean fileBean = fileBAO.saveFileAndGenerateFilename(oldMerchantProfileBean.getFileExtension(),
					    oldMerchantProfileBean.getContentType(), oldMerchantProfileBean.getLogoImageByteArray(),
					    "Merchant Logo");
				    if (fileBean != null && fileBean.getId() != null) {
					merchantProfileBean.setLogoId(fileBean.getId());
				    }
				}

				mapResult = merchantProfileBAO.createMerchantProfile(merchantProfileBean);

				if (mapResult != null) {
				    List<ErrorBean> errorBeans = (List<ErrorBean>) mapResult.get(List.class.getName() + "."
					    + ErrorBean.class.getName());
				    merchantProfileBean = (MerchantProfileBean) mapResult.get(MerchantProfileBean.class.getName());
				    if (errorBeans != null && !errorBeans.isEmpty()) {
					result.put(MessageBAO.MESSAGE_WARNING_TYPE, errorBeans);
				    } else {
					if (merchantProfileBean != null && merchantProfileBean.getId() != null) {

					    createMerchantProfileView.getImgMerchantLogo().setSource(null);
					    createMerchantProfileView.getImgMerchantLogo().setVisible(false);
					    createMerchantProfileView.getLayoutLogo().setWidth("300px");
					    createMerchantProfileView.getLayoutLogo().setHeight("150px");
					    createMerchantProfileView.getLblMerchantLogoHint().setVisible(true);
					    createMerchantProfileView.setMerchantProfileBean(merchantProfileBean);

					    uiCommonUtils.clearAllUIComponentWithPrefixDefaultValue(createMerchantProfileView, null);
					    result.put(MessageBAO.MESSAGE_INFO_TYPE,
						    "com.fw.ui.view.profile.CreateMerchantProfileView.message.created");
					} else {
					    result.put(MessageBAO.MESSAGE_WARNING_TYPE,
						    "com.fw.ui.view.profile.CreateMerchantProfileView.message.failed");
					}
				    }
				} else {
				    result.put(MessageBAO.MESSAGE_WARNING_TYPE, "message.error.common");
				}
			    } catch (Exception e) {
				result.put(MessageBAO.MESSAGE_WARNING_TYPE, "message.error.common");
			    }
			    // notification
			    notification(result);
			} else {
			    log.info("Cancel Confirm!");
			}
		    }
		}, "185px", "500px");

	return null;
    }

    @Override
    public boolean validate(ClickEvent event) {
	boolean validate = false;
	CreateMerchantProfileView createMerchantProfileView = (CreateMerchantProfileView) this.getBasedComponent();
	try {

	    uiCommonUtils.clearAllUIComponentNoInputFieldWithPrefix(createMerchantProfileView);

	    boolean merchantIdValid = createMerchantProfileView.getTxtMerchantId().isValid();
	    boolean merchantNameEnValid = createMerchantProfileView.getTxtMerchantNameEn().isValid();
	    boolean companyNameEnValid = createMerchantProfileView.getTxtCompanyNameEn().isValid();
	    boolean merchantServiceTypeValid = createMerchantProfileView.getCbbMerchantServiceType().isValid();
	    boolean businessRegistrationNumberValid = createMerchantProfileView.getTxtBusinessRegistrationNumber().isValid();
	    boolean countryDomicileValid = createMerchantProfileView.getCbbCountryDomicile().isValid();
	    boolean businessAddressValid = createMerchantProfileView.getTxtBusinessAddress().isValid();
	    boolean urlValid = createMerchantProfileView.getTxtUrl().isValid();
	    boolean taxIdValid = createMerchantProfileView.getTxtTaxId().isValid();
	    boolean isTestMerchantValid = createMerchantProfileView.getCbIsTestMerchant().isValid();
	    boolean projectContactNameValid = createMerchantProfileView.getTxtProjectContactName().isValid();
	    boolean projectContactPhoneValid = createMerchantProfileView.getTxtProjectContactPhone().isValid();
	    boolean projectContactMobileValid = createMerchantProfileView.getTxtProjectContactMobile().isValid();
	    boolean projectContactEmailAddressValid = createMerchantProfileView.getTxtProjectContactEmailAddress().isValid();
	    boolean technicalContactNameValid = createMerchantProfileView.getTxtTechnicalContactName().isValid();
	    boolean technicalContactPhoneValid = createMerchantProfileView.getTxtTechnicalContactPhone().isValid();
	    boolean technicalContactMobileValid = createMerchantProfileView.getTxtTechnicalContactMobile().isValid();
	    boolean technicalContactEmailAddressValid = createMerchantProfileView.getTxtTechnicalContactEmailAddress().isValid();

	    boolean statusValid = createMerchantProfileView.getCbbStatus().isValid();
	    boolean merchantNameThValid = createMerchantProfileView.getTxtMerchantNameTh().isValid();
	    boolean companyNameThValid = createMerchantProfileView.getTxtCompanyNameTh().isValid();
	    boolean mccCodeValid = createMerchantProfileView.getCbbMCCCode().isValid();
	    boolean statementNameValid = createMerchantProfileView.getTxtStatementName().isValid();
	    boolean countryRegionValid = createMerchantProfileView.getCbbCountryRegion().isValid();
	    boolean mailingAddressValid = createMerchantProfileView.getTxtMailingAddress().isValid();
	    boolean faxNumberValid = createMerchantProfileView.getTxtFaxNumber().isValid();
	    boolean enquiryNumberValid = createMerchantProfileView.getTxtEnquiryNumber().isValid();
	    boolean operationContactNameValid = createMerchantProfileView.getTxtOperationContactName().isValid();
	    boolean operationContactPhoneValid = createMerchantProfileView.getTxtOperationContactPhone().isValid();
	    boolean operationContactMobileValid = createMerchantProfileView.getTxtOperationContactMobile().isValid();
	    boolean operationContactEmailAddressValid = createMerchantProfileView.getTxtOperationContactEmailAddress().isValid();
	    boolean financialContactNameValid = createMerchantProfileView.getTxtFinancialContactName().isValid();
	    boolean financialContactPhoneValid = createMerchantProfileView.getTxtFinancialContactPhone().isValid();
	    boolean financialContactMobileValid = createMerchantProfileView.getTxtFinancialContactMobile().isValid();
	    boolean financialContactEmailAddressValid = createMerchantProfileView.getTxtFinancialContactEmailAddress().isValid();

	    if (merchantIdValid && merchantNameEnValid && companyNameEnValid && merchantServiceTypeValid && businessRegistrationNumberValid
		    && countryDomicileValid && businessAddressValid && urlValid && taxIdValid && isTestMerchantValid
		    && projectContactNameValid && projectContactPhoneValid && projectContactMobileValid && projectContactEmailAddressValid
		    && technicalContactNameValid && technicalContactPhoneValid && technicalContactMobileValid
		    && technicalContactEmailAddressValid && statusValid && merchantNameThValid && companyNameThValid && mccCodeValid
		    && statementNameValid && countryRegionValid && mailingAddressValid && faxNumberValid && enquiryNumberValid
		    && operationContactNameValid && operationContactPhoneValid && operationContactMobileValid
		    && operationContactEmailAddressValid && financialContactNameValid && financialContactPhoneValid
		    && financialContactMobileValid && financialContactEmailAddressValid) {
		Boolean isUnique = this.merchantProfileBAO.checkUniqueMerchantId(createMerchantProfileView.getTxtMerchantId().getValue());
		if (isUnique == null || !isUnique.booleanValue()) {
		    createMerchantProfileView.getTxtMerchantId().addStyleName("v-textfield-error");
		    createMerchantProfileView.getLblMerchantIdValidateMessage().setValue(
			    this.messageBAO.getMessage("com.fw.ui.view.profile.CreateMerchantProfileView.message.merchantId.exist"));
		    createMerchantProfileView.getLayoutMerchantIdValidate().setVisible(true);
		} else {
		    validate = true;
		}
	    } else {
		if (!merchantIdValid) {
		    createMerchantProfileView.getTxtMerchantId().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtMerchantId().getErrorMessage() != null) {
			createMerchantProfileView.getLblMerchantIdValidateMessage().setValue(
				createMerchantProfileView.getTxtMerchantId().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutMerchantIdValidate().setVisible(true);
		} else {
		    Boolean isUnique = this.merchantProfileBAO.checkUniqueMerchantId(createMerchantProfileView.getTxtMerchantId()
			    .getValue());
		    if (isUnique == null || !isUnique.booleanValue()) {
			createMerchantProfileView.getTxtMerchantId().addStyleName("v-textfield-error");
			createMerchantProfileView.getLblMerchantIdValidateMessage().setValue(
				this.messageBAO.getMessage("com.fw.ui.view.profile.CreateMerchantProfileView.message.merchantId.exist"));
			createMerchantProfileView.getLayoutMerchantIdValidate().setVisible(true);
		    }
		}
		if (!statusValid) {
		    createMerchantProfileView.getCbbStatus().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getCbbStatus().getErrorMessage() != null) {
			createMerchantProfileView.getLblStatusValidateMessage().setValue(
				createMerchantProfileView.getCbbStatus().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutStatusValidate().setVisible(true);
		}

		if (!merchantNameEnValid) {
		    createMerchantProfileView.getTxtMerchantNameEn().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtMerchantNameEn().getErrorMessage() != null) {
			createMerchantProfileView.getLblMerchantNameValidateMessageEn().setValue(
				createMerchantProfileView.getTxtMerchantNameEn().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutMerchantNameValidateEn().setVisible(true);
		}
		if (!merchantNameThValid) {
		    createMerchantProfileView.getTxtMerchantNameTh().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtMerchantNameTh().getErrorMessage() != null) {
			createMerchantProfileView.getLblMerchantNameValidateMessageTh().setValue(
				createMerchantProfileView.getTxtMerchantNameTh().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutMerchantNameValidateTh().setVisible(true);
		}

		if (!companyNameEnValid) {
		    createMerchantProfileView.getTxtCompanyNameEn().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtCompanyNameEn().getErrorMessage() != null) {
			createMerchantProfileView.getLblCompanyNameValidateMessageEn().setValue(
				createMerchantProfileView.getTxtCompanyNameEn().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutCompanyNameValidateEn().setVisible(true);
		}
		if (!companyNameThValid) {
		    createMerchantProfileView.getTxtCompanyNameTh().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtCompanyNameTh().getErrorMessage() != null) {
			createMerchantProfileView.getLblCompanyNameValidateMessageTh().setValue(
				createMerchantProfileView.getTxtCompanyNameTh().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutCompanyNameValidateTh().setVisible(true);
		}

		if (!merchantServiceTypeValid) {
		    createMerchantProfileView.getCbbMerchantServiceType().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getCbbMerchantServiceType().getErrorMessage() != null) {
			createMerchantProfileView.getLblMerchantServiceTypeValidateMessage().setValue(
				createMerchantProfileView.getCbbMerchantServiceType().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutMerchantServiceTypeValidate().setVisible(true);
		}
		if (!mccCodeValid) {
		    createMerchantProfileView.getCbbMCCCode().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getCbbMCCCode().getErrorMessage() != null) {
			createMerchantProfileView.getLblMCCCodeValidateMessage().setValue(
				createMerchantProfileView.getCbbMCCCode().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutMCCCodeValidate().setVisible(true);
		}

		if (!businessRegistrationNumberValid) {
		    createMerchantProfileView.getTxtBusinessRegistrationNumber().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtBusinessRegistrationNumber().getErrorMessage() != null) {
			createMerchantProfileView.getLblBusinessRegistrationNumberValidateMessage().setValue(
				createMerchantProfileView.getTxtBusinessRegistrationNumber().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutBusinessRegistrationNumberValidate().setVisible(true);
		}
		if (!statementNameValid) {
		    createMerchantProfileView.getTxtStatementName().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtStatementName().getErrorMessage() != null) {
			createMerchantProfileView.getLblStatementNameValidateMessage().setValue(
				createMerchantProfileView.getTxtStatementName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutStatementNameValidate().setVisible(true);
		}

		if (!countryDomicileValid) {
		    createMerchantProfileView.getCbbCountryDomicile().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getCbbCountryDomicile().getErrorMessage() != null) {
			createMerchantProfileView.getLblCountryDomicileValidateMessage().setValue(
				createMerchantProfileView.getCbbCountryDomicile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutCountryDomicileValidate().setVisible(true);
		}
		if (!countryRegionValid) {
		    createMerchantProfileView.getCbbCountryRegion().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getCbbCountryRegion().getErrorMessage() != null) {
			createMerchantProfileView.getLblCountryRegionValidateMessage().setValue(
				createMerchantProfileView.getCbbCountryRegion().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutCountryRegionValidate().setVisible(true);
		}

		if (!businessAddressValid) {
		    createMerchantProfileView.getTxtBusinessAddress().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtBusinessAddress().getErrorMessage() != null) {
			createMerchantProfileView.getLblBusinessAddressValidateMessage().setValue(
				createMerchantProfileView.getTxtBusinessAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutBusinessAddressValidate().setVisible(true);
		}
		if (!mailingAddressValid) {
		    createMerchantProfileView.getTxtMailingAddress().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtMailingAddress().getErrorMessage() != null) {
			createMerchantProfileView.getLblMailingAddressValidateMessage().setValue(
				createMerchantProfileView.getTxtMailingAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutMailingAddressValidate().setVisible(true);
		}

		if (!urlValid) {
		    createMerchantProfileView.getTxtUrl().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtUrl().getErrorMessage() != null) {
			createMerchantProfileView.getLblUrlValidateMessage().setValue(
				createMerchantProfileView.getTxtUrl().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutUrlValidate().setVisible(true);
		}
		if (!faxNumberValid) {
		    createMerchantProfileView.getTxtFaxNumber().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtFaxNumber().getErrorMessage() != null) {
			createMerchantProfileView.getLblFaxNumberValidateMessage().setValue(
				createMerchantProfileView.getTxtFaxNumber().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutFaxNumberValidate().setVisible(true);
		}

		if (!taxIdValid) {
		    createMerchantProfileView.getTxtTaxId().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtTaxId().getErrorMessage() != null) {
			createMerchantProfileView.getLblTaxIdValidateMessage().setValue(
				createMerchantProfileView.getTxtTaxId().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutTaxIdValidate().setVisible(true);
		}
		if (!enquiryNumberValid) {
		    createMerchantProfileView.getTxtEnquiryNumber().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtEnquiryNumber().getErrorMessage() != null) {
			createMerchantProfileView.getLblEnquiryNumberValidateMessage().setValue(
				createMerchantProfileView.getTxtEnquiryNumber().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutEnquiryNumberValidate().setVisible(true);
		}

		if (!isTestMerchantValid) {
		    createMerchantProfileView.getCbIsTestMerchant().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getCbIsTestMerchant().getErrorMessage() != null) {
			createMerchantProfileView.getLblIsTestMerchantValidateMessage().setValue(
				createMerchantProfileView.getCbIsTestMerchant().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutIsTestMerchantValidate().setVisible(true);
		}

		// project
		if (!projectContactNameValid) {
		    createMerchantProfileView.getTxtProjectContactName().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtProjectContactName().getErrorMessage() != null) {
			createMerchantProfileView.getLblProjectContactNameValidateMessage().setValue(
				createMerchantProfileView.getTxtProjectContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutProjectContactNameValidate().setVisible(true);
		}
		if (!projectContactPhoneValid) {
		    createMerchantProfileView.getTxtProjectContactPhone().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtProjectContactPhone().getErrorMessage() != null) {
			createMerchantProfileView.getLblProjectContactPhoneValidateMessage().setValue(
				createMerchantProfileView.getTxtProjectContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutProjectContactPhoneValidate().setVisible(true);
		}
		if (!projectContactMobileValid) {
		    createMerchantProfileView.getTxtProjectContactMobile().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtProjectContactMobile().getErrorMessage() != null) {
			createMerchantProfileView.getLblProjectContactMobileValidateMessage().setValue(
				createMerchantProfileView.getTxtProjectContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutProjectContactMobileValidate().setVisible(true);
		}
		if (!projectContactEmailAddressValid) {
		    createMerchantProfileView.getTxtProjectContactEmailAddress().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtProjectContactEmailAddress().getErrorMessage() != null) {
			createMerchantProfileView.getLblProjectContactEmailAddressValidateMessage().setValue(
				createMerchantProfileView.getTxtProjectContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutProjectContactEmailAddressValidate().setVisible(true);
		}
		// operation
		if (!operationContactNameValid) {
		    createMerchantProfileView.getTxtOperationContactName().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtOperationContactName().getErrorMessage() != null) {
			createMerchantProfileView.getLblOperationContactNameValidateMessage().setValue(
				createMerchantProfileView.getTxtOperationContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutOperationContactNameValidate().setVisible(true);
		}
		if (!operationContactPhoneValid) {
		    createMerchantProfileView.getTxtOperationContactPhone().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtOperationContactPhone().getErrorMessage() != null) {
			createMerchantProfileView.getLblOperationContactPhoneValidateMessage().setValue(
				createMerchantProfileView.getTxtOperationContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutOperationContactPhoneValidate().setVisible(true);
		}
		if (!operationContactMobileValid) {
		    createMerchantProfileView.getTxtOperationContactMobile().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtOperationContactMobile().getErrorMessage() != null) {
			createMerchantProfileView.getLblOperationContactMobileValidateMessage().setValue(
				createMerchantProfileView.getTxtOperationContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutOperationContactMobileValidate().setVisible(true);
		}
		if (!operationContactEmailAddressValid) {
		    createMerchantProfileView.getTxtOperationContactEmailAddress().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtOperationContactEmailAddress().getErrorMessage() != null) {
			createMerchantProfileView.getLblOperationContactEmailAddressValidateMessage().setValue(
				createMerchantProfileView.getTxtOperationContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutOperationContactEmailAddressValidate().setVisible(true);
		}
		// technical
		if (!technicalContactNameValid) {
		    createMerchantProfileView.getTxtTechnicalContactName().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtTechnicalContactName().getErrorMessage() != null) {
			createMerchantProfileView.getLblTechnicalContactNameValidateMessage().setValue(
				createMerchantProfileView.getTxtTechnicalContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutTechnicalContactNameValidate().setVisible(true);
		}
		if (!technicalContactPhoneValid) {
		    createMerchantProfileView.getTxtTechnicalContactPhone().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtTechnicalContactPhone().getErrorMessage() != null) {
			createMerchantProfileView.getLblTechnicalContactPhoneValidateMessage().setValue(
				createMerchantProfileView.getTxtTechnicalContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutTechnicalContactPhoneValidate().setVisible(true);
		}
		if (!technicalContactMobileValid) {
		    createMerchantProfileView.getTxtTechnicalContactMobile().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtTechnicalContactMobile().getErrorMessage() != null) {
			createMerchantProfileView.getLblTechnicalContactMobileValidateMessage().setValue(
				createMerchantProfileView.getTxtTechnicalContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutTechnicalContactMobileValidate().setVisible(true);
		}
		if (!technicalContactEmailAddressValid) {
		    createMerchantProfileView.getTxtTechnicalContactEmailAddress().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtTechnicalContactEmailAddress().getErrorMessage() != null) {
			createMerchantProfileView.getLblTechnicalContactEmailAddressValidateMessage().setValue(
				createMerchantProfileView.getTxtTechnicalContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutTechnicalContactEmailAddressValidate().setVisible(true);
		}
		// financial
		if (!financialContactNameValid) {
		    createMerchantProfileView.getTxtFinancialContactName().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtFinancialContactName().getErrorMessage() != null) {
			createMerchantProfileView.getLblFinancialContactNameValidateMessage().setValue(
				createMerchantProfileView.getTxtFinancialContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutFinancialContactNameValidate().setVisible(true);
		}
		if (!financialContactPhoneValid) {
		    createMerchantProfileView.getTxtFinancialContactPhone().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtFinancialContactPhone().getErrorMessage() != null) {
			createMerchantProfileView.getLblFinancialContactPhoneValidateMessage().setValue(
				createMerchantProfileView.getTxtFinancialContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutFinancialContactPhoneValidate().setVisible(true);
		}
		if (!financialContactMobileValid) {
		    createMerchantProfileView.getTxtFinancialContactMobile().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtFinancialContactMobile().getErrorMessage() != null) {
			createMerchantProfileView.getLblFinancialContactMobileValidateMessage().setValue(
				createMerchantProfileView.getTxtFinancialContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutFinancialContactMobileValidate().setVisible(true);
		}
		if (!financialContactEmailAddressValid) {
		    createMerchantProfileView.getTxtFinancialContactEmailAddress().addStyleName("v-textfield-error");
		    if (createMerchantProfileView.getTxtFinancialContactEmailAddress().getErrorMessage() != null) {
			createMerchantProfileView.getLblFinancialContactEmailAddressValidateMessage().setValue(
				createMerchantProfileView.getTxtFinancialContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    createMerchantProfileView.getLayoutFinancialContactEmailAddressValidate().setVisible(true);
		}

	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return validate;
    }
}
